{include file="public/layout.htm" /}
<body class="back-c">
    <div class="ey-content">
        <div class="item-wrap-box" style="display: block;">
            <div class="item-wrap mt0">
                <form id="postForm">
                    <input type="hidden" name="status" value="7">
                    <input type="hidden" name="last_one" value="{$Service.last_one}">
                    <input type="hidden" name="users_id" value="{$Service.users_id}">
                    <input type="hidden" name="order_id" value="{$Service.order_id}">
                    <input type="hidden" name="order_code" value="{$Order.order_code}">
                    <input type="hidden" name="details_id" value="{$Service.details_id}">
                    <input type="hidden" name="service_id" value="{$Service.service_id}">
                    <input type="hidden" name="product_id" value="{$Service.product_id}">
                    <input type="hidden" name="product_name" value="{$Service.product_name}">
                    <input type="hidden" name="service_type" value="{$Service.service_type}">
                    <input type="hidden" name="order_status" value="{$Order.order_status}">
                    <input type="hidden" name="refund_code" value="{$Service.refund_code}">
                    <div class="order-list">
                        <div class="list-left">商品总额</div>
                        <div class="list-right">
                            <div class="ey-input">
                                {empty name="$Order.points_shop_order"}￥{/empty}{$Service.refund_price}
                            </div>
                        </div>
                    </div>
                    <div class="order-list">
                        <div class="list-left">实际退回余额</div>
                        <div class="list-right">
                            <div class="ey-input">
                                <div class="ey-input-wrapper">
                                    <input type="text" value="{$Service.actual_price}" data-price="{$Service.actual_price}" name="actual_price" id="actual_price" class="ey-input-input" onpaste='this.value=this.value.replace(/^\D*([0-9]\d*\.?\d{0,2})?.*$/, "$1");' onkeyup='this.value=this.value.replace(/^\D*([0-9]\d*\.?\d{0,2})?.*$/, "$1"); actualPrice(this);'>
                                </div>
                            </div>
                        </div>
                    </div>
                    {notempty name="$Order.points_shop_order"}
                    <div class="order-list">
                        <div class="list-left">实际退回积分</div>
                        <div class="list-right">
                            <div class="ey-input">
                                <div class="ey-input-wrapper">
                                    <input type="text" value="{$Service.actual_points}" data-points="{$Service.actual_points}" name="actual_points" id="actual_points" class="ey-input-input" onpaste='this.value=this.value.replace(/^\D*([0-9]\d*)?.*$/, "$1");' onkeyup='this.value=this.value.replace(/^\D*([0-9]\d*)?.*$/, "$1"); actualPoints(this);'>
                                </div>
                            </div>
                        </div>
                    </div>
                    {/notempty}
                    <div class="order-list">
                        <div class="list-left">退款方式</div>
                        <div class="list-right">
                            <div class="select">
                                <select class="pd0" name="refund_way" id="refund_way">
                                    <option value="1" {eq name="$Service.refund_way" value="1"} selected {/eq}>退款到余额{notempty name="$Order.points_shop_order"}(积分){/notempty}</option>
                                    <option value="2" {eq name="$Service.refund_way" value="2"} selected {/eq}>线下退款</option>
                                    <option value="3" {eq name="$Service.refund_way" value="3"} selected {/eq} {neq name="$Order.pay_name" value="wechat"} disabled {/neq}>原路退回(微信)</option>
                                </select>
                            </div>
                            <i class="iconfont icon-right"></i>
                        </div>
                    </div>
                    <div class="order-list">
                        <div class="list-left">退款说明</div>
                        <div class="list-right">
                            <div class="ey-input">
                                <div class="ey-input-wrapper">
                                    <input type="text" name="refund_remark" class="ey-input-input" placeholder="选填">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <div class="w100-footer-wrap fixed-footer-wrap">
            <button class="w50-btn-no" id="unifiedJump" onclick="unifiedJump(this);" data-url="{:weapp_url('Mbackend/Shop/after_service_details', ['service_id' => $Service.service_id])}">返回</button>
            <button class="w50-btn" onclick="submitServiceRefund();">确定</button>
        </div>
    </div>
</body>
<script type="text/javascript">
    // 验证实际退款金额是否超过
    function actualPrice(obj) {
        var value = $(obj).val();
        var price = $(obj).data('price');
        if (parseFloat(value) > parseFloat(price)) {
            $(obj).val(price);
        } else {
            $(obj).val(value);
        }
    }

    // 验证实际退款积分是否超过
    function actualPoints(obj) {
        var value = $(obj).val();
        var price = $(obj).data('points');
        if (parseInt(value) > parseInt(price)) {
            $(obj).val(price);
        } else {
            $(obj).val(value);
        }
    }

    // 表单提交
    function submitServiceRefund() {
        console.log($('#refund_way').val());
        if (!$('#refund_way').val()) {
            layerMsg('请选择退款方式', 1);
            return false;
        }
        var actualPrice = $('#actual_price').val();
        if (isNaN(actualPrice) || 0 > parseFloat(actualPrice)) {
            layerMsg('实际退款余额不能小于0', 1);
            $('#actual_price').focus();
            return false;
        }
        layerLoading();
        $.ajax({
            type: "post",
            url : "{:url('ShopService/after_service_handle', ['_ajax'=>1, 'weappAjax'=>1])}",
            data: $('#postForm').serialize(),
            dataType: 'json',
            success: function (res) {
                layer.closeAll();
                if (res.code == 1) {
                    if (!res.data.email && !res.data.mobile && !res.data.weChat) {
                        layerMsg(res.msg, 1, function() {
                            $('#unifiedJump').click();
                        });
                    } else {
                        if (res.data.email) unifySendEmail(res.data.email);
                        if (res.data.mobile) unifySendMobile(res.data.mobile);
                        if (res.data.weChat) unifySendWeChat(res.data.weChat);
                        layerMsg(res.msg, 1, function() {
                            $('#unifiedJump').click();
                        });
                    }
                } else {
                    layerAlert(res.msg);
                }
            },
            error:function(e){
                layer.closeAll();
                layerAlert(e.responseText);
            }
        });
    }
</script> 
{include file="public/footer.htm" /}